//
//  WXSUserModel.m
//  SleepBooks
//
//  Created by 王勇 on 16/9/10.
//  Copyright © 2016年 rimi. All rights reserved.
//

#import "WXSUserModel.h"
#define kUsernameKey @"username"
#define kPasswordKey @"password"
#define kIsLoginKey @"isLogin"

@interface WXSUserModel ()
@property (nonatomic,strong) NSUserDefaults *defaults;

@end


@implementation WXSUserModel
@synthesize username = _username;
@synthesize password = _password;

+(instancetype)shareUserValue{
    static WXSUserModel *userModel = nil;
    if (userModel == nil) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            userModel = [[WXSUserModel alloc]init];
        });
    }
    return userModel;
}

#pragma mark - GETTER & SETTER
-(void)setUserName:(NSString *)userName{
    _username = userName;
    [self.defaults setObject:userName forKey:kUsernameKey];
}

-(void)setPassword:(NSString *)password{
    _password = password;
    [self.defaults setObject:password forKey:kPasswordKey];
}

-(NSString *)userName{
    
    _username = [self.defaults objectForKey:kUsernameKey];
    
    return  _username;
}

-(NSString *)password{
    _password = [self.defaults objectForKey:kPasswordKey];
    return _password;
}


-(NSUserDefaults *)defaults{
    if (!_defaults) {
        _defaults = [NSUserDefaults standardUserDefaults];
    }
    return  _defaults;
}

@end
